package com.woniu.controller;

import com.woniu.pojo.Power;
import com.woniu.service.PowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("power")
public class powerController {
    @Autowired
    PowerService powerService;

    /*
     * 增加权限id
     */
    @RequestMapping("addOready")
    @ResponseBody
    public Map<String,Object> addOready(Power power){
        Map<String,Object> map=new HashMap<>();
        try {


            Integer integer = powerService.addOready(power);
            if(integer!=null){
                map.put("powerId",integer);
                map.put("result","ok");
            }else{
                map.put("result","error");
            }

        } catch (Exception e) {
            map.put("result","error");
            e.printStackTrace();
        }

        return map;
    }
    /*
    * 增加权限
    */
    @RequestMapping("add")
    @ResponseBody
    public Map<String,Object> add(Power power){
        Map<String,Object> map=new HashMap<>();
        try {
            powerService.add(power);
            map.put("result","ok");
        } catch (Exception e) {
            map.put("result","error");
            e.printStackTrace();
        }

        return map;
    }
    /*
     * 查找所有权限
     */
    @RequestMapping("findAll")
    @ResponseBody
    public List<Power> findAll(){
        List<Power> all=null;
        try {
             all = powerService.findAll();

        } catch (Exception e) {

            e.printStackTrace();
        }

        return all;
    }
    //跳转至权限表单
    @RequestMapping("power")
    public String power(){
        return "WEB-INF/power/power";
    }
}
